// $Id: networktopologizerring.cpp 40 2004-09-27 08:20:26Z hansemil $
#include "networktopologizerring.h"
#include <list>

/**
 * @param nodes A pointer to the Node STL list
 * @test Test that it does what it's supposed to under correct routing
 */
NetworkTopologizerRing::NetworkTopologizerRing(list<Node *> *nodes)
	: NetworkTopologizer(nodes)
{
	// Variables to hold previous nodes
	Node *preprev, *prev;
	int preprevKey, prevKey;

	// Assign initial previous nodes
	std::list<Node *>::iterator tnode=(*m_nodes).end();
	prev = *(--tnode);
	preprev = *(--tnode);
	preprevKey = nodeKeys[(*m_nodes).size()-2];
	prevKey = nodeKeys[(*m_nodes).size()-1];

	// Build topology
	int i = 0;
	for (std::list<Node *>::iterator node=(*m_nodes).begin(); node!=(*m_nodes).end(); node++) {

		// Add neighbors to previous node
		prev->addNeighbor(preprev, preprevKey);
		prev->addNeighbor(*node, nodeKeys[i]);
		//cout << prev << " gets neighbor " << preprev << " key(" << preprevKey << ")" << "\tand " << *node << " key(" << nodeKeys[i] << ")" << endl;

		// Rotate previous nodes
		preprev = prev;
		prev = *node;
		preprevKey = prevKey;
		prevKey = nodeKeys[i++];
	}
}

NetworkTopologizerRing::~NetworkTopologizerRing()
{
}
